<template>
  <div class="viewcontainer" v-if="dataset">
    <el-row class="view-header">
      <el-col :span="22">
        <hi-lquery v-bind="queryPanel" :target="dataset"></hi-lquery>
      </el-col>
      <el-col :span="2" style="text-align: right">
        <el-button type="primary" @click="showAdd">新增</el-button>
      </el-col>
    </el-row>
    <el-row class="view-main">
      <el-table
        ref="dataTable"
        :data="dataset.data"
        height="100%"
        style="width: 100%"
        v-loading="dataset.loading"
      >
        <el-table-column type="index" width="50" />
        <el-table-column prop="apply_no" label="单号" width="160" />
        <el-table-column prop="apply_money_yuan" label="申请金额" width="160">
          <template slot-scope="scope">
            {{ formatMoney(scope.row.apply_money_yuan) }}
          </template>
        </el-table-column>
        <el-table-column prop="payee_name" label="收款人姓名" width="160" />
        <el-table-column prop="bank_name" label="银行名称" width="160" />
        <el-table-column prop="bank_account" label="银行帐号" width="160" />
        <el-table-column prop="fee_yuan" label="手续费">
          <template slot-scope="scope">
            {{ formatMoney(scope.row.fee_yuan) }}
          </template>
        </el-table-column>
        <el-table-column prop="create_date" label="创建时间" width="160" />
        <el-table-column prop="FAUDIT" label="审核" width="80">
          <template slot-scope="scope">
            <withdrawTag v-model="scope.row.FAUDIT"></withdrawTag>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="80">
          <template slot-scope="scope">
            <hi-taskopen
              :row="scope.row"
              @opentask="showEdit"
              :type="'apply_no'"
            >
              <el-button type="text" size="small" v-if="scope.row.FAUDIT == 1">
                <i class="el-icon-edit"></i>
              </el-button>
            </hi-taskopen>
            <hi-taskopen
              :row="scope.row"
              @opentask="showEdit"
              :type="'apply_no'"
            >
              <el-button type="text" v-if="scope.row.FAUDIT != 1" size="small">
                <i class="el-icon-tickets"></i>
              </el-button>
            </hi-taskopen>
            <el-button
              type="text"
              v-if="scope.row.FAUDIT == 1"
              size="small"
              @click="remove(scope.row)"
            >
              <i class="el-icon-delete"></i>
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row class="view-footer pagebar">
      <hi-pagination
        background
        :total="dataset.total"
        :target="dataset"
      ></hi-pagination>
    </el-row>
  </div>
</template>

<script>
import { utils } from "hi-ui";
import viewBase from "../../base";
import withdrawCfg from "./dataset";
import withdrawTag from "@/views/component/withdrawTag";
export default {
  name: "withdrawlist",
  extends: viewBase,
  components: {
    withdrawTag,
  },
  data() {
    let datasetCfg = Object.assign({}, withdrawCfg, {
      action: "autoAction",
    });
    return {
      //数据桥梁
      dataBridge: new Map(),
      dataset: null,
      //查询面板配置
      queryPanel: {
        columnsTotal: 2,
        fields: [
          {
            element: "el-input",
            label: "单号",
            name: "apply_no",
          },
        ],
      },

      //数据集配置
      datasetCfg: datasetCfg,
      total: 100,
    };
  },
  model: {
    prop: "value",
    event: "valuechange",
  },
  props: {
    value: {
      type: Object,
    },
  },

  computed: {},
  watch: {},
  methods: {
    formatMoney(val) {
      return utils.number.format(val, "￥");
    },
    // 添加
    showAdd() {
      this.openByPath("/finance/withdraw/flow/txsq.flow", null, {
        title: "新增提现申请",
      });
    },
    // 编辑
    showEdit(taskopen, taskinfo) {
      let data = taskopen.row;
      debugger;
      let pcform = taskinfo.task.pcform;
      if (pcform == "finance/withdraw/detail") {
        //旧数据兼容
        pcform = "finance/withdraw/flow/txsq";
      }
      this.openByPath(
        `/${pcform}.flow?__fnumber=${data.apply_no}`,
        {
          id: data.record_id,
        },
        {
          title: data.apply_no + (data.FAUDIT == 1 ? "编辑" : "详情"),
          target: "_blank",
        }
      );
    },
    //删除
    remove(data) {
      this.$confirm("确定要删除【" + data.apply_no + "】", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let saveHelper = this.createSaveHelper(this.dataset.modelFile);
          saveHelper.remove(data);
          saveHelper.save().then((res) => {
            this.dataset.reload();
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {});
    },
  },
  mounted() {
    //创建主数据集
    this.dataset = this.createDataSet(this.datasetCfg);
    this.dataBridge.set(this.dataset, ["dataTable"]);
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scope>
</style>
